package com.platform.common.util.query;

import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.platform.common.util.GsonUtils;
import com.platform.common.util.query.constant.Operator;
import com.platform.common.util.query.constant.ResourceType;
import com.platform.common.util.query.vo.Condition;
import com.platform.common.util.query.vo.Fields;
import com.platform.common.util.query.vo.Group;
import com.platform.common.util.query.vo.Page;
import com.platform.common.util.query.vo.Root;

public class RootTest {

	@Test
	public void test() {

		//
		Fields files = QueryUtils.setFiles("AreaCode", Operator.equal, "10000", Operator.and);
		Fields files1 = QueryUtils.setFiles("AreaCode", Operator.equal, "10000", Operator.and);
		Fields fi2 = QueryUtils.setFiles("beginTime", Operator.equal, "2017-09-20", Operator.and);
		Fields fi12 = QueryUtils.setFiles("endTime", Operator.equal, "2017-09-20");
		Group group = QueryUtils.setGroup(Operator.and, files, files1, fi2, fi12);

		// 子查询条件
		Fields files2 = QueryUtils.setFiles("AreaCode2", Operator.equal, "10000", Operator.and);
		Fields files12 = QueryUtils.setFiles("AreaCode2", Operator.equal, "10000");
		Group group2 = QueryUtils.setGroup(null, files2, files12);
		// 添加组
		group.setGroup(group2);
		List<Group> setGroupList = QueryUtils.setGroupList(group);

		// 查询条件
		Condition condition = QueryUtils.setCondition(setGroupList);
		// 分页参数
		Page page = QueryUtils.setPage(1, 30);

		// 总查询条件
		Root root = QueryUtils.setRoot(ResourceType.Base_Cyber, condition, page, "time desc ", "time","2017-09-20","2017-09-29");

		// 转化为json
		String josn = GsonUtils.parseBeanToJson(root);
		System.out.println(josn);

		String resString = "{'selectID':false,'resourceType':'Base_Cyber','condition':{'group':{'fields':[{'field':'AreaCode','op':'equeal','value':'10000'},{'field':'AreaCode','op':'equeal','value':'10000'}],'opt':'','group':{'fields':[{'field':'AreaCode2','op':'equeal','value':'10000'},{'field':'AreaCode2','op':'equeal','value':'10000'}],'opt':''}}},'page':{'pageIndex':1,'pageCount':30},'orderBy':'time desc ','groupBy':'time'}";

		Root jsonToBean = GsonUtils.parseJsonToBean(Root.class, josn);
		System.out.println(jsonToBean);

		Map<String, Object> condition2 = QueryUtils.getCondition(root);
		System.out.println(condition2);

	}

}
